package com.wu.cloud.account.config;

import bean.PeskResponseEntity;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import util.ResponseUtil;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @author xwu36
 */
@ControllerAdvice
@ResponseBody
public class ControllerAdviceComponent {
    private static final Logger LOG = LoggerFactory.getLogger(ControllerAdviceComponent.class);

    @ExceptionHandler(value = Exception.class)
    public PeskResponseEntity commonExceptionHandler(HttpServletRequest request, HttpServletResponse response, Exception e) {
        LOG.error("请求来自" + request.getRequestURI() + "的Service执行失败:" + e.getMessage(), e);
        return ResponseUtil.fail("远程调用Service失败");
    }
}
